# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=SDL
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.15+r419+gef3a6c05
pkgrel=1
pkgdesc="A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://libsdl.org"
msys2_references=(
  "cpe: cpe:/a:libsdl:libsdl"
  "cpe: cpe:/a:libsdl:simple_directmedia_layer"
)
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools" 'git')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-libiconv")
_commit=ef3a6c05beb9523895a1ba7e53d322ec5b7c806b # main
source=("git+https://github.com/libsdl-org/SDL-1.2#commit=${_commit}"
        "0001-sdl-config-win-paths.patch")
sha256sums=('SKIP'
            '3b88cde73a06f204b607093d864224b094b189a98d1c1c5a7e9ceb69e7ef7bd7')

pkgver() {
  cd SDL-1.2
  git describe --tags | sed 's/^release-//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd SDL-1.2
  git apply "${srcdir}"/0001-sdl-config-win-paths.patch
  ./autogen.sh
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../SDL-1.2/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-assembly \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
  sed -e "s|-mwindows||g" -i "${pkgdir}"${MINGW_PREFIX}/lib/pkgconfig/sdl.pc
}
